<template>

	<!-- 门店申请 -->
	<view class="form-page" v-if="shopinfo == null">
		<view class="form-title">门店申请</view>
		<view class="form-item"><text>门店名称（必填）</text><input class="input-text" v-model="form.store_name"
				placeholder="请输入门店名称" /></view>
		<view class="form-item"><text>联系人姓名（必填）</text><input v-model="form.name" placeholder="请输入联系人姓名" /></view>
		<view class="form-item"><text>联系人电话（必填）</text><input  v-model="form.phone" placeholder="请输入联系人电话" type="number" disabled="true"/></view>
		
		<view class="form-item">
			<text>身份证正面（必传）</text>
			<view class="upload-box">
				<view v-if="form.idcard_front" class="img-wrap">
					<image :src="web_url + form.idcard_front" mode="aspectFill" class="img"></image>
					<view class="delete-btn" @click="form.idcard_front = ''">×</view>
				</view>
				<view v-else class="add-btn" @click="chooseImage('idcard_front')">+</view>
			</view>
		</view>
		<view class="form-item"><text>身份证背面（必传）</text>
			<view class="upload-box">
				<view v-if="form.idcard_back" class="img-wrap">
					<image :src="web_url + form.idcard_back" mode="aspectFill" class="img"></image>
					<view class="delete-btn" @click="form.idcard_back = ''">×</view>
				</view>
				<view v-else class="add-btn" @click="chooseImage('idcard_back')">+</view>
			</view>
		</view>
		<view class="form-item"><text>营业执照（必传）</text>
			<view class="upload-box">
				<view v-if="form.license" class="img-wrap">
					<image :src="web_url + form.license" mode="aspectFill" class="img"></image>
					<view class="delete-btn" @click="form.license = ''">×</view>
				</view>
				<view v-else class="add-btn" @click="chooseImage('license')">+</view>
			</view>
		</view>

		<view class="form-item"><text>门店LOGO（必传）</text>
			<view class="upload-box">
				<view v-if="form.shop_logo_image" class="img-wrap">
					<image :src="web_url + form.shop_logo_image" mode="aspectFill" class="img"></image>
					<view class="delete-btn" @click="form.shop_logo_image = ''">×</view>
				</view>
				<view v-else class="add-btn" @click="chooseImage('shop_logo_image')">+</view>
			</view>
		</view>
		<view class="form-item"><text>门店图片</text>
			<view class="upload-box">
				<view v-if="form.shop_image" class="img-wrap">
					<image :src="web_url + form.shop_image" mode="aspectFill" class="img"></image>
					<view class="delete-btn" @click="form.shop_image = ''">×</view>
				</view>
				<view v-else class="add-btn" @click="chooseImage('shop_image')">+</view>
			</view>
		</view>
		<view class="form-item">
			<!-- <text>培训环境</text>
			<textarea v-model="form.env_text" placeholder="环境描述（可选）" /> -->
			<text>门店图集（最多 5 张）</text>
			<view class="upload-box">
				<block v-for="(img, index) in form.shop_images" :key="index">
					<view class="img-wrap">
						<image :src="web_url + img" mode="aspectFill" class="img" />
						<view class="delete-btn" @click="removeShopImage(index)">×</view>
					</view>
				</block>
				<view v-if="form.shop_images.length < 5" class="add-btn" @click="chooseShopImages">+</view>
			</view>
		</view>
		<!-- <view class="form-item"><text>对公信息</text><input v-model="form.account" placeholder="请输入开户名" /></view>
		<view class="form-item"><input type="number" v-model="form.accounthao" placeholder="请输入银行账号" /></view>
		<view class="form-item"><input v-model="form.accounthang" placeholder="请输入开户行" /></view> -->
		<view class="form-item"><text>简介</text><textarea v-model="form.intro" placeholder="请输入机构简介" /></view>
		<view class="form-item"><text>培训特色</text><textarea v-model="form.feature" placeholder="请输入培训特色" /></view>
		
		<view class="form-item">
			<!-- <text>培训环境</text>
			<textarea v-model="form.env_text" placeholder="环境描述（可选）" /> -->
			<text>培训环境（图片，最多 5 张）</text>
			<view class="upload-box">
				<block v-for="(img, index) in form.env_imgs" :key="index">
					<view class="img-wrap">
						<image :src="web_url + img" mode="aspectFill" class="img" />
						<view class="delete-btn" @click="removeImage(index)">×</view>
					</view>
				</block>
				<view v-if="form.env_imgs.length < 5" class="add-btn" @click="chooseTrainImage">+</view>
			</view>
		</view>
		<view class="form-item">
			<text>培训视频（最多 2 个）</text>
			<view class="upload-box">
				<block v-for="(video, index) in form.env_videos" :key="index">
					<view class="img-wrap">
						<video :src="web_url + video" class="video" />
						<view class="delete-btn" @click="removeVideo(index)">×</view>
					</view>
				</block>
				<view v-if="form.env_videos.length < 2" class="add-btn" @click="chooseVideo">+</view>
			</view>
		</view>
		<view class="form-item"><text>详细地址</text><input v-model="form.address" placeholder="请输入地址" /></view>
		<view class="form-item"><text>门店接受抽佣百分比</text><input v-model="form.accept_pay" placeholder="请输入1-100数字" /></view>
		<view class="form-item">
			<text>绑定商务代理（必选）</text>
			<picker mode="selector" :range="staffList" range-key="staff_name" @change="onStaffChange">
				<view class="picker">
					{{ selectedStaffName || '请选择绑定商务代理' }}
				</view>
			</picker>
		</view>
		<view class="form-item"><text>门店账户（必填）</text><input type="number" v-model="form.username" placeholder="请输入登录账号" /></view>
		<view class="form-item"><input type="number" v-model="form.password" placeholder="请输入登录密码" /></view>

		<!-- 修改按钮文本 -->
		<button class="form-btn" @click="submit">提交申请</button>
	</view>








	<!-- 审核中 -->
	<view v-else-if="shopinfo != null&&shopinfo.state==1">
		<view class="form-title" style="color:#fff;margin: 0px;font-size:32rpx;padding:10rpx 0px;background:#FFCF00;">
			审核中</view>
		<view class="form-page">
			<view class="form-item"><text>门店名称</text><input class="input-text" v-model="shopinfo.shop_name"
					placeholder="请输入门店名称" /></view>
			<view class="form-item"><text>联系人姓名</text><input v-model="shopinfo.shop_contacts" placeholder="请输入联系人姓名"
					disabled="true" /></view>
			<view class="form-item"><text>联系人电话</text><input v-model="shopinfo.shop_mobile" placeholder="请输入联系人电话"
					type="number" disabled="true" /></view>
			
			<view class="form-item">
				<text>身份证正面（必传）</text>
				<view class="upload-box">
					<view v-if="shopinfo.idcard_add" class="img-wrap">
						<image :src="web_url + shopinfo.idcard_add" mode="aspectFill" class="img"></image>
						<!-- <view class="delete-btn" @click="shopinfo.idcard_add = ''">×</view> -->
					</view>
					<view v-else class="add-btn" @click="chooseImage('idcard_add')">+</view>
				</view>
			</view>
			<view class="form-item"><text>身份证背面（必传）</text>
				<view class="upload-box">
					<view v-if="shopinfo.idcard_cut" class="img-wrap">
						<image :src="web_url + shopinfo.idcard_cut" mode="aspectFill" class="img"></image>
						<!-- <view class="delete-btn" @click="shopinfo.idcard_cut = ''">×</view> -->
					</view>
					<view v-else class="add-btn" @click="chooseImage('idcard_cut')">+</view>
				</view>
			</view>
			<view class="form-item"><text>营业执照（必传）</text>
				<view class="upload-box">
					<view v-if="shopinfo.trade" class="img-wrap">
						<image :src="web_url + shopinfo.trade" mode="aspectFill" class="img"></image>
						<!-- <view class="delete-btn" @click="shopinfo.trade = ''">×</view> -->
					</view>
					<view v-else class="add-btn" @click="chooseImage('trade')">+</view>
				</view>
			</view>

			<view class="form-item"><text>门店LOGO（必传）</text>
				<view class="upload-box">
					<view v-if="shopinfo.shop_logo_image" class="img-wrap">
						<image :src="web_url + shopinfo.shop_logo_image" mode="aspectFill" class="img"></image>
						<!-- <view class="delete-btn" @click="shopinfo.shop_logo_image = ''">×</view> -->
					</view>
					<view v-else class="add-btn" @click="chooseImage('shop_logo_image')">+</view>
				</view>
			</view>
			<view class="form-item"><text>门店图片</text>
				<view class="upload-box">
					<view v-if="shopinfo.shop_image" class="img-wrap">
						<image :src="web_url + shopinfo.shop_image" mode="aspectFill" class="img"></image>
						<!-- <view class="delete-btn" @click="shopinfo.shop_logo_image = ''">×</view> -->
					</view>
					<view v-else class="add-btn" @click="chooseImage('shop_image')">+</view>
				</view>
			</view>
			<view class="form-item">
				<!-- <text>培训环境</text> -->
				<!-- <textarea v-model="shopinfo.env_text" placeholder="环境描述（可选）"  disabled="true"/> -->
				<text>门店图集（最多 5 张）</text>
				<view class="upload-box">
					<block v-for="(img, index) in shopinfo.shop_images" :key="index">
						<view class="img-wrap">
							<image :src="web_url + img" mode="aspectFill" class="img" />
							<!-- <view class="delete-btn" @click="removeImage(index)">×</view> -->
						</view>
					</block>
					<!-- <view v-if="shopinfo.train_vibe_videos.length < 5" class="add-btn" @click="chooseTrainImage">+</view> -->
				</view>
			</view>
			<!-- <view class="form-item"><text>对公信息</text><input v-model="shopinfo.account" placeholder="请输入开户名"
					disabled="true" /></view>
			<view class="form-item"><input v-model="shopinfo.accounthao" placeholder="请输入银行账号" disabled="true" /></view>
			<view class="form-item"><input v-model="shopinfo.accounthang" placeholder="请输入开户行" disabled="true" /></view> -->
			<view class="form-item"><text>简介</text><textarea v-model="shopinfo.train_trait" placeholder="请输入机构简介"
					disabled="true" /></view>
			<view class="form-item"><text>培训特色</text><textarea v-model="shopinfo.shop_info" placeholder="请输入培训特色"
					disabled="true" /></view>
			
			<view class="form-item">
				<!-- <text>培训环境</text> -->
				<!-- <textarea v-model="shopinfo.env_text" placeholder="环境描述（可选）"  disabled="true"/> -->
				<text>培训环境（图片，最多 5 张）</text>
				<view class="upload-box">
					<block v-for="(img, index) in shopinfo.train_vibe_videos" :key="index">
						<view class="img-wrap">
							<image :src="web_url + img" mode="aspectFill" class="img" />
							<!-- <view class="delete-btn" @click="removeImage(index)">×</view> -->
						</view>
					</block>
					<!-- <view v-if="shopinfo.train_vibe_videos.length < 5" class="add-btn" @click="chooseTrainImage">+</view> -->
				</view>
			</view>
			<view class="form-item">
				<text>培训视频（最多 2 个）</text>
				<view class="upload-box">
					<block v-for="(video, index) in shopinfo.train_videos" :key="index">
						<view class="img-wrap">
							<video :src="web_url + video" class="video" />
							<!-- <view class="delete-btn" @click="removeVideo(index)">×</view> -->
						</view>
					</block>
					<!-- <view v-if="shopinfo.train_videos.length < 2" class="add-btn" @click="chooseVideo">+</view> -->
				</view>
			</view>
			<view class="form-item"><text>地址</text><input v-model="shopinfo.address" placeholder="请输入地址"
					disabled="true" /></view>
			<view class="form-item"><text>门店接受抽佣百分比</text><input v-model="shopinfo.accept_pay" placeholder="请输入1-100数字" /></view>
			<view class="form-item">
				<text>绑定商务代理（必选）</text>
				<view class="picker">
					{{ shopinfo.staffname}}
				</view>
			</view>
			<view class="form-item"><text>门店账户</text><input v-model="shopinfo.username" placeholder="请输入登录账号"
					disabled="true" /></view>
			<view class="form-item"><input v-model="shopinfo.password" placeholder="请输入登录密码" disabled="true" /></view>

			<!-- 修改按钮文本 -->
			<button class="form-btn">正在审核，请稍等</button>
		</view>
	</view>







	<!-- 审核已驳回 -->
	<view v-else-if="shopinfo != null&&shopinfo.state==3">
		<view class="form-title" style="color:#fff;margin: 0px;font-size:32rpx;padding:10rpx 0px;background:red;"
			@click="cxshenqing">审核已驳回，请重新提交</view>
		<view class="form-title" style="margin: 0px;background-color: #181818;font-size: 24rpx;padding: 5px 0px;">
			驳回原因：{{ shopinfo.reason }}</view>
		<view class="form-page">
			<view class="form-item"><text>门店名称（必填）</text><input class="input-text" v-model="shopinfo.shop_name"
					placeholder="请输入门店名称" /></view>
			<view class="form-item"><text>联系人姓名（必填）</text><input v-model="shopinfo.shop_contacts" placeholder="请输入联系人姓名"
					disabled="true" /></view>
			<view class="form-item"><text>联系人电话（必填）</text><input v-model="shopinfo.shop_mobile" placeholder="请输入联系人电话"
					type="number" disabled="true" /></view>
			
			<view class="form-item">
				<text>身份证正面（必传）</text>
				<view class="upload-box">
					<view v-if="shopinfo.idcard_add" class="img-wrap">
						<image :src="web_url + shopinfo.idcard_add" mode="aspectFill" class="img"></image>
						<!-- <view class="delete-btn" @click="shopinfo.idcard_add = ''">×</view> -->
					</view>
					<view v-else class="add-btn" @click="chooseImage('idcard_add')">+</view>
				</view>
			</view>
			<view class="form-item"><text>身份证背面（必传）</text>
				<view class="upload-box">
					<view v-if="shopinfo.idcard_cut" class="img-wrap">
						<image :src="web_url + shopinfo.idcard_cut" mode="aspectFill" class="img"></image>
						<!-- <view class="delete-btn" @click="shopinfo.idcard_cut = ''">×</view> -->
					</view>
					<view v-else class="add-btn" @click="chooseImage('idcard_cut')">+</view>
				</view>
			</view>
			<view class="form-item"><text>营业执照（必传）</text>
				<view class="upload-box">
					<view v-if="shopinfo.trade" class="img-wrap">
						<image :src="web_url + shopinfo.trade" mode="aspectFill" class="img"></image>
						<!-- <view class="delete-btn" @click="shopinfo.trade = ''">×</view> -->
					</view>
					<view v-else class="add-btn" @click="chooseImage('trade')">+</view>
				</view>
			</view>

			<view class="form-item"><text>门店LOGO（必传）</text>
				<view class="upload-box">
					<view v-if="shopinfo.shop_logo_image" class="img-wrap">
						<image :src="web_url + shopinfo.shop_logo_image" mode="aspectFill" class="img"></image>
						<!-- <view class="delete-btn" @click="shopinfo.shop_logo_image = ''">×</view> -->
					</view>
					<view v-else class="add-btn" @click="chooseImage('shop_logo_image')">+</view>
				</view>
			</view>
			<view class="form-item"><text>门店图片</text>
				<view class="upload-box">
					<view v-if="shopinfo.shop_image" class="img-wrap">
						<image :src="web_url + shopinfo.shop_image" mode="aspectFill" class="img"></image>
						<!-- <view class="delete-btn" @click="shopinfo.shop_logo_image = ''">×</view> -->
					</view>
					<view v-else class="add-btn" @click="chooseImage('shop_image')">+</view>
				</view>
			</view>
			<view class="form-item">
				<!-- <text>培训环境</text> -->
				<!-- <textarea v-model="shopinfo.env_text" placeholder="环境描述（可选）"  disabled="true"/> -->
				<text>门店图集（最多 5 张）</text>
				<view class="upload-box">
					<block v-for="(img, index) in shopinfo.shop_images" :key="index">
						<view class="img-wrap">
							<image :src="web_url + img" mode="aspectFill" class="img" />
							<!-- <view class="delete-btn" @click="removeImage(index)">×</view> -->
						</view>
					</block>
					<!-- <view v-if="shopinfo.train_vibe_videos.length < 5" class="add-btn" @click="chooseTrainImage">+</view> -->
				</view>
			</view>
			<!-- <view class="form-item"><text>对公信息</text><input v-model="shopinfo.account" placeholder="请输入开户名"
					disabled="true" /></view>
			<view class="form-item"><input v-model="shopinfo.accounthao" placeholder="请输入银行账号" disabled="true" /></view>
			<view class="form-item"><input v-model="shopinfo.accounthang" placeholder="请输入开户行" disabled="true" /></view> -->
			<view class="form-item"><text>简介</text><textarea v-model="shopinfo.train_trait" placeholder="请输入机构简介"
					disabled="true" /></view>
			<view class="form-item"><text>培训特色</text><textarea v-model="shopinfo.shop_info" placeholder="请输入培训特色"
					disabled="true" /></view>
			
			<view class="form-item">
				<!-- <text>培训环境</text> -->
				<!-- <textarea v-model="shopinfo.env_text" placeholder="环境描述（可选）"  disabled="true"/> -->
				<text>培训环境（图片，最多 5 张）</text>
				<view class="upload-box">
					<block v-for="(img, index) in shopinfo.train_vibe_videos" :key="index">
						<view class="img-wrap">
							<image :src="web_url + img" mode="aspectFill" class="img" />
							<!-- <view class="delete-btn" @click="removeImage(index)">×</view> -->
						</view>
					</block>
					<!-- <view v-if="shopinfo.train_vibe_videos.length < 5" class="add-btn" @click="chooseTrainImage">+</view> -->
				</view>
			</view>
			<view class="form-item">
				<text>培训视频（最多 2 个）</text>
				<view class="upload-box">
					<block v-for="(video, index) in shopinfo.train_videos" :key="index">
						<view class="img-wrap">
							<video :src="web_url + video" class="video" />
							<!-- <view class="delete-btn" @click="removeVideo(index)">×</view> -->
						</view>
					</block>
					<!-- <view v-if="shopinfo.train_videos.length < 2" class="add-btn" @click="chooseVideo">+</view> -->
				</view>
			</view>
			<view class="form-item"><text>地址</text><input v-model="shopinfo.address" placeholder="请输入地址"
					disabled="true" /></view>
			<view class="form-item"><text>门店接受抽佣百分比</text><input disabled="true" v-model="shopinfo.accept_pay" placeholder="请输入1-100数字" /></view>

			<view class="form-item">
				<text>绑定商务代理</text>
				<view class="picker">
					{{ shopinfo.staffname}}
				</view>
			</view>
			<view class="form-item"><text>门店账户</text><input v-model="shopinfo.username" placeholder="请输入登录账号"
					disabled="true" /></view>
			<view class="form-item"><input v-model="shopinfo.password" placeholder="请输入登录密码" disabled="true" /></view>

			<!-- 修改按钮文本 -->
			<button class="form-btn" @click="cxshenqing" style="background-color: red;color: #fff;">审核已驳回，重新提交</button>
		</view>

	</view>
</template>

<script>
	import uploads from "@/util/upload.js";
	const webConfig = require("@/util/config");
	export default {
		data() {
			return {
				form: {
					store_name: '',
					name: '',
					phone: '',
					idcard_front: '',
					idcard_back: '',
					license: '',
					account: '',
					accounthao: '',
					accounthang: '',
					username: '',
					password: '',
					shop_logo_image: '',
					address: '',
					feature: '',
					intro: '',
					env_text: '',
					accept_pay:'',
					env_imgs: [],
					shop_image: '',
					shop_images: [],
					env_videos: [],
					staff_id: '',
				},
				userinfo: null,
				shopinfo: null,
				web_url: '',
				staffList: [],
				selectedStaffIndex: -1,
				staff_id:null,
			}
		},
		onLoad(options) {
			
			this.web_url = webConfig.base_url || '';
			this.loadStaffList();
			this.getUserInfo();
			this.staff_id = options.staff_id;

		},
		computed: {

			selectedStaffName() {
				let _this = this;
				if(this.staff_id){
					this.staffList.forEach(function(item,index){
						if(item.id==_this.staff_id){
							_this.selectedStaffIndex = index;
							_this.form.staff_id = _this.staff_id;
						}
					})
				}
				if (this.selectedStaffIndex === -1) return '';
				const staff = this.staffList[this.selectedStaffIndex];
				return staff ? staff.staff_name : '';
				
				
			}
		},
		mounted() {
			this.$http({
				url: "/addons/xilufitness/shop/staff"
			}).then(res => {
				console.log(res);
			})
		},
		methods: {
			onStaffChange(e) {
				const index = e.detail.value;
				const selected = this.staffList[index];
				this.selectedStaffIndex = index;
				this.form.staff_id = selected.id;
			},
			loadStaffList() {
				this.$http({
					url: "/addons/xilufitness/shop/staff"
				}).then(res => {
					this.staffList = res.data.list || [];
				});
			},
			getThaliList() {
				this.$http({
					url: '/addons/xilufitness/shop/thali',
					method: 'GET'
				}).then(res => {
					// res.data.list 格式如 [{ id, thali_name, thali_amount }]
					this.subscriptionOptions = (res.data.list || []).map(item => ({
						value: item.id,
						label: item.thali_name,
						price: Number(item.thali_amount),
						desc: item.thali_more || ''
					}))
					// 默认选第一个套餐
					if (this.subscriptionOptions.length) {
						this.form.subscriptionType = this.subscriptionOptions[0].value
					}
				})
			},

			getUserInfo() {
				let _this = this;
				this.$http({
					url: '/addons/xilufitness/user/index',
					method: 'get'
				}).then(res => {
					if (res.code == 1) {
						_this.form.phone = res.data.info.mobile;
						_this.shopinfo = res.data.info.shopinfo;
						_this.shopinfo.train_vibe_videos = _this.shopinfo.train_vibe_videos.split(",");
						_this.shopinfo.train_videos = _this.shopinfo.train_videos.split(",");
						_this.shopinfo.shop_images = _this.shopinfo.shop_images.split(",");
						_this.shopinfo.accept_pay = _this.shopinfo.accept_pay*100+'%';
						console.log(_this.shopinfo)
					}
				}).catch(error => {
					console.log('userError', error);
				})
			},

			createOrder() {

				// 校验讲师信息（至少1个，名字和特色不能为空）
				for (let i = 0; i < this.form.teachers.length; i++) {
					const t = this.form.teachers[i];
					if (!t.name || !t.feature) {
						return uni.showToast({
							title: `请完善第 ${i + 1} 位讲师信息`,
							icon: 'none'
						});
					}
				}
				// Example: Replace with your actual payment integration logic (for WeChat payment)
				let _this = this;
				this.$http({
					url: '/addons/xilufitness/pay/index',
					data: {
						id: 1,
					},
					method: 'post'
				}).then(res => {
					if (res.code === 1) {
						// Call WeChat payment API here
						_this.wechatPay(res.data);
					} else {
						uni.showToast({
							title: res.msg || '支付失败',
							icon: 'none'
						});
					}
				}).catch(error => {
					uni.showToast({
						title: '支付接口调用失败',
						icon: 'none'
					});
					console.error('Payment Error:', error);
				});
			},

			wechatPay(data) {
				// Example: Replace with your actual WeChat payment integration logic
				let _this = this;
				this.$api.toPay(data, function(res) {
					// Payment successful, proceed with form submission
					_this.submit()
				}, function(error) {
					uni.showToast({
						title: '支付失败',
						icon: 'none'
					});
					console.error('WeChat Pay Error:', error);
				});
			},


			resetForm() {
				// Clear form fields after successful submission
				this.form = {
					store_name: '',
					name: '',
					// Reset other fields as needed
					subscriptionType: 'monthly' // Default selection
				};
			},

			chooseImage(field) {
				let _this = this;
				uni.chooseImage({
					count: 1,
					success(res) {
						const tempPath = res.tempFilePaths[0];
						uni.showLoading({
							title: '上传中...'
						});
						uploads.uploadFile(tempPath, function(uploadRes) {
							uni.hideLoading();
							if (uploadRes.code === 1) {
								_this.form[field] = uploadRes.data.url;
							} else {
								uni.showToast({
									title: uploadRes.msg || '上传失败',
									icon: 'none'
								});
							}
						});
					}
				});
			},

			chooseTrainImage() {
				let _this = this;
				const maxCount = 5 - this.form.env_imgs.length;
				if (maxCount <= 0) return;
				uni.chooseImage({
					count: maxCount,
					success(res) {
						const tempFiles = res.tempFilePaths;
						let uploadCount = 0;
						uni.showLoading({
							title: '上传中...'
						});
						tempFiles.forEach(tempPath => {
							uploads.uploadFile(tempPath, function(uploadRes) {
								uploadCount++;
								if (uploadRes.code === 1) {
									_this.form.env_imgs.push(uploadRes.data.url);
								} else {
									uni.showToast({
										title: uploadRes.msg || '上传失败',
										icon: 'none'
									});
								}
								if (uploadCount === tempFiles.length) {
									uni.hideLoading();
								}
							});
						});
					}
				});
			},
			chooseShopImages() {
				let _this = this;
				const maxCount = 5 - this.form.shop_images.length;
				if (maxCount <= 0) return;
				uni.chooseImage({
					count: maxCount,
					success(res) {
						const tempFiles = res.tempFilePaths;
						let uploadCount = 0;
						uni.showLoading({
							title: '上传中...'
						});
						tempFiles.forEach(tempPath => {
							uploads.uploadFile(tempPath, function(uploadRes) {
								uploadCount++;
								if (uploadRes.code === 1) {
									_this.form.shop_images.push(uploadRes.data.url);
								} else {
									uni.showToast({
										title: uploadRes.msg || '上传失败',
										icon: 'none'
									});
								}
								if (uploadCount === tempFiles.length) {
									uni.hideLoading();
								}
							});
						});
					}
				});
			},
			chooseVideo() {
				let _this = this;
				if (this.form.env_videos.length >= 2) {
					uni.showToast({
						title: '最多上传2个视频',
						icon: 'none'
					});
					return;
				}
				uni.chooseVideo({
					sourceType: ['album', 'camera'],
					success(res) {
						const tempPath = res.tempFilePath;
						uni.showLoading({
							title: '上传中...'
						});
						uploads.uploadFile(tempPath, function(uploadRes) {
							uni.hideLoading();
							if (uploadRes.code === 1) {
								_this.form.env_videos.push(uploadRes.data.url);
							} else {
								uni.showToast({
									title: uploadRes.msg || '上传失败',
									icon: 'none'
								});
							}
						});
					}
				});
			},

			removeImage(index) {
				this.form.env_imgs.splice(index, 1);
			},
			removeShopImage(index) {
				this.form.shop_images.splice(index, 1);
			},
			removeVideo(index) {
				this.form.env_videos.splice(index, 1);
			},

			addTeacher() {
				this.form.teachers.push({
					name: '',
					feature: ''
				});
			},
			removeTeacher(i) {
				this.form.teachers.splice(i, 1);
			},
			//重新提交申请
			cxshenqing() {
				this.shopinfo = null;
			},
			//提交申请
			submit() {
				if (!this.form.store_name) {
					return uni.showToast({
						title: '请输入门店名称',
						icon: 'none'
					});
				}
				if (!this.form.name) {
					return uni.showToast({
						title: '请输入联系人姓名',
						icon: 'none'
					});
				}
				if (!this.form.phone) {
					return uni.showToast({
						title: '请输入联系电话',
						icon: 'none'
					});
				}
				const phoneReg = /^1[3-9]\d{9}$/;
				if (!phoneReg.test(this.form.phone)) {
					return uni.showToast({
						title: '手机号格式不正确',
						icon: 'none'
					});
				}
				if (!this.form.idcard_front) {
					return uni.showToast({
						title: '请上传身份证正面',
						icon: 'none'
					});
				}
				if (!this.form.idcard_back) {
					return uni.showToast({
						title: '请上传身份证反面',
						icon: 'none'
					});
				}
				if (!this.form.license) {
					return uni.showToast({
						title: '请上传营业执照',
						icon: 'none'
					});
				}
				// if (!this.form.intro) {
				// 	return uni.showToast({
				// 		title: '请输入门店简介',
				// 		icon: 'none'
				// 	});
				// }
				// if (!this.form.feature) {
				// 	return uni.showToast({
				// 		title: '请输入培训特色',
				// 		icon: 'none'
				// 	});
				// }

				// if (!this.form.account) {
				// 	return uni.showToast({
				// 		title: '请输入开户名',
				// 		icon: 'none'
				// 	});
				// }

				// if (!this.form.accounthao) {
				// 	return uni.showToast({
				// 		title: '请输入银行账号',
				// 		icon: 'none'
				// 	});
				// }

				// if (!this.form.accounthang) {
				// 	return uni.showToast({
				// 		title: '请输入开户行',
				// 		icon: 'none'
				// 	});
				// }

				if (!this.form.username) {
					return uni.showToast({
						title: '请输入登录账号',
						icon: 'none'
					});
				}

				if (!this.form.password) {
					return uni.showToast({
						title: '请输入登录密码',
						icon: 'none'
					});
				}
				if (!this.form.shop_logo_image) {
					return uni.showToast({
						title: '请上传门店LOGO',
						icon: 'none'
					});
				}
				let _this = this
				this.$http({
					url: '/addons/xilufitness/shop/apply',
					method: 'POST',
					data: {
						shop_name: this.form.store_name,
						shop_contacts: this.form.name,
						shop_mobile: this.form.phone,
						idcard_add: this.form.idcard_front,
						idcard_cut: this.form.idcard_back,
						trade: this.form.license,
						shop_info: this.form.intro,
						train_trait: this.form.feature,
						address:this.form.address,
						account: this.form.account,
						accounthao: this.form.accounthao,
						accounthang: this.form.accounthang,

						username: this.form.username,
						password: this.form.password,

						shop_logo_image: this.form.shop_logo_image,
						shop_image: this.form.shop_image,
						shop_images: this.form.shop_images,
						accept_pay: this.form.accept_pay,
						train_vibe_videos: this.form.env_imgs,
						train_videos: this.form.env_videos,
						// train_videos: ['/uploads/20250722/c3f0e052e7316ccea156d7ceea1fdf59.mp4'],
						id: this.form.staff_id
					}
				}).then(res => {
					let code = res.code
					if (code == 1) {
						uni.showToast({
							title: res.msg,
							icon: 'success',
							success() {
								console.log(code);
								console.log(_this.$api);
								setTimeout(() => {
									if (code == 1) {
										_this.$api.navigate("../mine/mine")
									}
								}, 2000)
							
							}
						});
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
					// 可选：清空表单、跳转等
				}).catch(err => {
					uni.showToast({
						title: err.msg || '提交失败',
						icon: 'none'
					});
				});
			}
		}
	}
</script>

<style scoped>
	.radio-group {
		margin-top: 20rpx;
	}

	.radio-item {
		display: flex;
		flex-direction: column;
		padding: 20rpx;
		margin-bottom: 15rpx;
		background-color: #232323;
		border-radius: 12rpx;
	}

	.radio-content {
		display: flex;
		align-items: center;
	}

	.radio-content text {
		margin-left: 15rpx;
		color: #fff;
	}

	.radio-desc {
		margin-top: 10rpx;
		margin-left: 55rpx;
		font-size: 24rpx;
		color: #999;
	}

	.total-amount {
		margin: 40rpx 0;
		text-align: center;
		font-size: 32rpx;
		color: #fff;
	}

	.amount {
		color: #FFCF00;
		font-weight: bold;
		font-size: 36rpx;
	}

	.form-item {
		margin-bottom: 28rpx;
	}

	.section-title {
		color: #FFCF00;
		font-size: 30rpx;
		font-weight: 600;
		margin-bottom: 20rpx;
	}

	/* 	.teacher-card {
	  background: #2c2c2c;
	  border-radius: 12rpx;
	  padding: 24rpx 20rpx 20rpx;
	  margin-bottom: 20rpx;
	  position: relative;
	  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.3);
	} */

	.input-field {
		width: 100%;
		background: #383838;
		color: #fff;
		border: none;
		border-radius: 10rpx;
		padding: 18rpx 20rpx;
		font-size: 28rpx;
		box-sizing: border-box;
		/* 关键 */
		margin-bottom: 16rpx;
		min-height: 60rpx;
		/* 适当高度 */
		line-height: 1.3;
	}

	.teacher-card {
		position: relative;
		background-color: #2c2c2c;
		border-radius: 12rpx;
		padding: 24rpx 20rpx 20rpx;
		margin-bottom: 20rpx;
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.2);
		display: flex;
		flex-direction: column;
		gap: 20rpx;
	}

	.btn-delete {
		position: absolute;
		top: 12rpx;
		right: 12rpx;
		width: 44rpx;
		height: 44rpx;
		line-height: 44rpx;
		text-align: center;
		font-size: 36rpx;
		color: #fff;
		background-color: #e55353;
		border-radius: 50%;
		box-shadow: 0 0 8rpx rgba(229, 83, 83, 0.6);
		cursor: pointer;
		user-select: none;
		transition: background-color 0.3s ease;
	}

	.btn-delete:hover {
		background-color: #d43d3d;
	}

	.btn-add {
		display: block;
		width: 90%;
		margin: 30rpx auto 0;
		background: #FFCF00;
		color: #181818;
		font-size: 32rpx;
		padding: 22rpx 0;
		border-radius: 16rpx;
		text-align: center;
		cursor: pointer;
		box-shadow: 0 4rpx 12rpx rgba(255, 207, 0, 0.5);
		transition: background-color 0.3s ease;
	}

	.btn-add:hover {
		background: #e6b800;
	}


	.form-page {
		background-color: #E8EEFE;
		min-height: 100vh;
		padding: 30rpx;
		color: #333;
		box-sizing: border-box;
	}

	.form-title {
		font-size: 40rpx;
		color: #FFCF00;
		margin-bottom: 40rpx;
		text-align: center;
		font-weight: bold;
	}

	.form-item {
		margin-bottom: 40rpx;
		display: flex;
		flex-direction: column;
		gap: 20rpx;
	}

	.form-item text {
		color: #333;
		font-size: 28rpx;
		font-weight: 500;
	}

	input,
	textarea {
		background-color: #fff;
		color: #333;
		border: 1px solid #E8EEFE;
		border-radius: 12rpx;
		width: 92%;
		padding: 24rpx;
		font-size: 28rpx;
		box-sizing: content-box;
		transition: 0.2s;
	}

	input:focus,
	textarea:focus {
		border-color: #FFCF00;
		box-shadow: 0 0 10rpx rgba(255, 207, 0, 0.5);
		outline: none;
	}

	textarea {
		min-height: 120rpx;
		line-height: 1.5;
		resize: none;
	}

	.picker {
		background-color: #fff;
		color: #333;
		border: 1px solid #E8EEFE;
		border-radius: 12rpx;
		padding: 24rpx;
		font-size: 28rpx;
		transition: 0.2s;
	}

	.picker:active {
		border-color: #FFCF00;
		box-shadow: 0 0 10rpx rgba(255, 207, 0, 0.5);
	}

	.upload-box {
		display: flex;
		gap: 20rpx;
		flex-wrap: wrap;
	}

	.img-wrap {
		position: relative;
		width: 160rpx;
		height: 160rpx;
		border-radius: 12rpx;
		overflow: hidden;
	}

	.img,
	.video {
		width: 100%;
		height: 100%;
		object-fit: cover;
		border-radius: 12rpx;
	}

	.delete-btn {
		position: absolute;
		top: 0;
		right: 0;
		width: 40rpx;
		height: 40rpx;
		line-height: 40rpx;
		text-align: center;
		background: rgba(0, 0, 0, 0.5);
		color: #fff;
		border-bottom-left-radius: 12rpx;
		font-size: 30rpx;
	}

	.add-btn {
		width: 160rpx;
		height: 160rpx;
		background-color: #fff;
		color: #999;
		font-size: 60rpx;
		text-align: center;
		line-height: 160rpx;
		border-radius: 12rpx;
	}

	.form-btn {
		background-color: #FFCF00;
		color: #181818;
		border-radius: 16rpx;
		font-size: 32rpx;
		width: 90%;
		margin: 60rpx auto 0;
		display: block;
		text-align: center;
		padding: 24rpx 0;
		box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.4);
		transition: 0.2s;
	}

	.form-btn:active {
		transform: scale(0.96);
		opacity: 0.8;
	}
</style>